/*
 * Copyright (C) 2012 nutmotion <simonotmanuel@gmail.com>
 * Originally released under the tradeUplan project (wiki is at Expression project.wiki is undefined on line 5, column 85 in Templates/Licenses/license-gpl30.txt.)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.nutmotion.model.jpa;

import java.io.Serializable;
import java.util.Collection;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author nutmotion <simonotmanuel@gmail.com>
 */
@Entity
@Table(name = "\"user\"")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "User.findAll", query = "SELECT u FROM User u"),
    @NamedQuery(name = "User.findById", query = "SELECT u FROM User u WHERE u.id = :id"),
    @NamedQuery(name = "User.findByNickname", query = "SELECT u FROM User u WHERE u.nickname = :nickname")})
public class User implements Serializable {
        @OneToMany(cascade = CascadeType.ALL, mappedBy = "user")
    private Collection<Trade> tradeCollection;
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Integer id;
    @Basic(optional = false)
    @Column(name = "nickname")
    private String nickname;
        @OneToMany(cascade = CascadeType.ALL, mappedBy = "user")
    private Collection<Direction> directionCollection;
        @OneToMany(cascade = CascadeType.ALL, mappedBy = "user")
    private Collection<Tag> tagCollection;
        @OneToMany(cascade = CascadeType.ALL, mappedBy = "user")
    private Collection<Timeframe> timeframeCollection;
        @OneToMany(cascade = CascadeType.ALL, mappedBy = "user")
    private Collection<Signal> signalCollection;
        @OneToMany(cascade = CascadeType.ALL, mappedBy = "user")
    private Collection<Analysis> analysisCollection;

    public User() {
    }

    public User(Integer id) {
        this.id = id;
    }

    public User(Integer id, String nickname) {
        this.id = id;
        this.nickname = nickname;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getNickname() {
        return nickname;
    }

    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

    @XmlTransient
    public Collection<Direction> getDirectionCollection() {
        return directionCollection;
    }

    public void setDirectionCollection(Collection<Direction> directionCollection) {
        this.directionCollection = directionCollection;
    }

    @XmlTransient
    public Collection<Tag> getTagCollection() {
        return tagCollection;
    }

    public void setTagCollection(Collection<Tag> tagCollection) {
        this.tagCollection = tagCollection;
    }

    @XmlTransient
    public Collection<Timeframe> getTimeframeCollection() {
        return timeframeCollection;
    }

    public void setTimeframeCollection(Collection<Timeframe> timeframeCollection) {
        this.timeframeCollection = timeframeCollection;
    }

    @XmlTransient
    public Collection<Signal> getSignalCollection() {
        return signalCollection;
    }

    public void setSignalCollection(Collection<Signal> signalCollection) {
        this.signalCollection = signalCollection;
    }

    @XmlTransient
    public Collection<Analysis> getAnalysisCollection() {
        return analysisCollection;
    }

    public void setAnalysisCollection(Collection<Analysis> analysisCollection) {
        this.analysisCollection = analysisCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof User)) {
            return false;
        }
        User other = (User) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.nutmotion.common.User[ id=" + id + " ]";
    }

    @XmlTransient
    public Collection<Trade> getTradeCollection() {
        return tradeCollection;
    }

    public void setTradeCollection(Collection<Trade> tradeCollection) {
        this.tradeCollection = tradeCollection;
    }
    
}
